// xc_lshop/api/jtklm/meituan/meituan.js
// var actbill = require('../../../../xc/model/jtklm')
var actbill = require('../../model/jtklm.js')

var app = getApp();

Page({
  mixins: [require('../../../../xc/mixins/basicMixin')],

  /**
   * 页面的初始数据
   */
  data: {
    CustomBar: app.globalData.CustomBar,
    navval: "1",
    nav: [{
        val: "1",
        name: "外卖"
      },
      {
        val: "2",
        name: "商超"
      },
      {
        val: "3",
        name: "优选"
      },
      {
        val: "6",
        name: "酒店"
      },
      {
        val: "10",
        name: "周末"
      },
      // {val:"4",name:"优选1.99促销页"},
      // {val:"5",name:"优选秒杀栏目活动"},
      // {val:"7",name:"美团优选新人活动页"},
    ],
    basicurl: "-1",
    list: {},
    text:{
      1:"餐前福利！外卖红包天天领！最高可得66元！",
      2:"低价好货！商超红包天天领！最高可得10元！",
      3:"团购好货！限时1分钱买菜！尽在美团优选！",
      6:"出行无忧！酒店红包天天领！最高可得50元！",
      10:"周末特价！特价红包天天领！最高可得20元！",
    }
  },
  xcloaddata: function (options, config) {

    this.setconfig(config)

    this.geturl('Meituan', this.data.navval)
  },
  setconfig(config) {

    if (config['jtklmapi']) {
      if (config['jtklmapi']['status'] == -1) {

        this.pageback()
      } else {
        this.setData({
          mtui: config['jtklmapi']['ui']['meituan']
        })
      }
    }else{
      this.pageback()
    }
    console.log("this.data.mtui")
    console.log(this.data.mtui)

  },
  shareposter() {

    var xcposter = this.selectComponent("#xcposter");
    var mtui = this.data.mtui;
    var type = this.data.navval;

    var bgimg = mtui[type]['poster']; //"http://md.cohooo.net/attachment/images/2/2021/10/PsmAyyuxmzA4YTwmS7XK4y7979XfI9.png"

    if(type==10){
      var qrimg = this.data.list[type]['miniProgramQrCode']; //"http://p0.meituan.net/poiqrcode/74062c815334f1f98f369fd8e6657d9a100811.jpg"
    }else{
      var qrimg = this.data.list[type]['we_app_info']['miniCode']; //"http://p0.meituan.net/poiqrcode/74062c815334f1f98f369fd8e6657d9a100811.jpg"
    }

    xcposter.init(type, bgimg, qrimg)
  },
  onClick(e){
  //  console.log(e)
   this.setData({
    navval: e.detail.name,
  })
  },
  onChange(e) {

    this.setData({
      navval: e.detail.name,
    })

    if (!this.data.list[e.detail.name]) {
      this.geturl('Meituan', e.detail.name)
      if (e.detail.name == 3) {
        this.geturl('Meituan', 4)
        this.geturl('Meituan', 5)
        this.geturl('Meituan', 7)
      }
    }


  },
  
  nav(e) {
    console.log("e")
    console.log(e)
    // var type= this.data.navval
    var dataset = e.currentTarget.dataset
    if (dataset.type) {
      var type = dataset.type
      var item = this.data.list[type];
      if (item) {
        var we_app_info = item['we_app_info']
        wx.navigateToMiniProgram({
          appId: we_app_info['app_id'],
          path: we_app_info['page_path'],
          fail(e) {
            console.log(e)
          }
        })
      }
    }





  },
  geturl(source, type) {
    var that = this;
    actbill.geturl(source, type).then(function (res) {
    
      if (res['status'] == 1) {
        var name = 'list[' + type + ']';
        that.setData({
          [name]: res['data']
        })
        // var we_app_info=res['data']['we_app_info']
        // wx.navigateToMiniProgram({
        //   appId:we_app_info['app_id'],
        //   path:we_app_info['page_path']
        // })
        // that.setData({
        //   url:res['data']['h5_url']
        // })
      }

    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

 
})